package com.yanqu.road.entity.activity.douluodalu.data;

import com.alibaba.fastjson.JSON;
import com.yanqu.road.entity.DataObject;
import com.yanqu.road.entity.FieldTypeAnnotation;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;

@FieldTypeAnnotation(tableName = "t_u_douluodalu_user_data")
public class DouLuoDaLuServerUserData extends DataObject {

    @FieldTypeAnnotation(select = true, update = true, desc = "活动ID")
    private int activityId;

    @FieldTypeAnnotation(update = true, desc = "玩家ID")
    private long userId;

    @FieldTypeAnnotation(desc = "派遣次数")
    private int sendTimes;

    @FieldTypeAnnotation(desc = "挑战次数")
    private int fightTimes;

    @FieldTypeAnnotation(desc = "追捕次数")
    private int zhuiBuTimes;

    @FieldTypeAnnotation(desc = "重置时间")
    private long resetTime;

    @FieldTypeAnnotation(desc = "玩家触发商品的时间 k:商品id v:最近的触发时间")
    private Map<Integer,Integer> touchMallMap = new ConcurrentHashMap<>();

    @FieldTypeAnnotation(desc = "最后读战报的时间")
    private long lastReadReportTime;

    //盲合抽奖
    @FieldTypeAnnotation(desc = "总抽盲盒次数")
    private int totalTimes;
    @FieldTypeAnnotation(desc = "盲盒奖励")
    private List<Integer> drawBoxList = new ArrayList<>();
    @FieldTypeAnnotation(desc = "前六是否有大奖")
    private boolean getSharedBox;

    @FieldTypeAnnotation(desc = "距上次抽中隐藏款的次数")
    private int commonTimes;

    private long triedStoneNum;
    //触发礼包次数
    private Map<Integer,Integer> touchMallTimesMap = new ConcurrentHashMap<>();

    public int getActivityId() {
        return activityId;
    }

    public void setActivityId(int activityId) {
        if(this.activityId != activityId) {
            this.activityId = activityId;
            setUpdateOption();
        }
    }

    public long getUserId() {
        return userId;
    }

    public void setUserId(long userId) {
        if(this.userId != userId) {
            this.userId = userId;
            setUpdateOption();
        }
    }

    public int getSendTimes() {
        return sendTimes;
    }

    public void setSendTimes(int sendTimes) {
        if(this.sendTimes != sendTimes) {
            this.sendTimes = sendTimes;
            setUpdateOption();
        }
    }

    public int getFightTimes() {
        return fightTimes;
    }

    public void setFightTimes(int fightTimes) {
        if(this.fightTimes != fightTimes) {
            this.fightTimes = fightTimes;
            setUpdateOption();
        }
    }

    public int getZhuiBuTimes() {
        return zhuiBuTimes;
    }

    public void setZhuiBuTimes(int zhuiBuTimes) {
        if(this.zhuiBuTimes != zhuiBuTimes) {
            this.zhuiBuTimes = zhuiBuTimes;
            setUpdateOption();
        }
    }

    public long getResetTime() {
        return resetTime;
    }

    public void setResetTime(long resetTime) {
        if(this.resetTime != resetTime) {
            this.resetTime = resetTime;
            setUpdateOption();
        }
    }

    public Map<Integer, Integer> getTouchMallMap() {
        return touchMallMap;
    }

    public String getTouchMallMapJsonStr() {
        return JSON.toJSONString(touchMallMap);
    }

    public void setTouchMallMap(Map<Integer, Integer> touchMallMap) {
        this.touchMallMap = touchMallMap;
        setUpdateOption();
    }

    public int getTouchMallTime(int mallId){
        if(touchMallMap.containsKey(mallId)){
            return touchMallMap.get(mallId);
        }
        return 0;
    }

    public void setTouchMallTime(int mallId, int time){
        touchMallMap.put(mallId, time);
        setUpdateOption();
    }

    public void removeTouchMall(int mallId){
        touchMallMap.remove(mallId);
        setUpdateOption();
    }

    public int getTotalTimes() {
        return totalTimes;
    }

    public void setTotalTimes(int totalTimes) {
        if(this.totalTimes != totalTimes) {
            this.totalTimes = totalTimes;
            setUpdateOption();
        }
    }

    public List<Integer> getDrawBoxList() {
        return drawBoxList;
    }

    public void setDrawBoxList(List<Integer> drawBoxList) {
        this.drawBoxList = drawBoxList;
    }

    public boolean isGetSharedBox() {
        return getSharedBox;
    }

    public void setGetSharedBox(boolean getSharedBox) {
        if(this.getSharedBox != getSharedBox) {
            this.getSharedBox = getSharedBox;
            setUpdateOption();
        }
    }

    public int getCommonTimes() {
        return commonTimes;
    }

    public void setCommonTimes(int commonTimes) {
        if(this.commonTimes != commonTimes) {
            this.commonTimes = commonTimes;
            setUpdateOption();
        }
    }

    public long getLastReadReportTime() {
        return lastReadReportTime;
    }

    public void setLastReadReportTime(long lastReadReportTime) {
        if(this.lastReadReportTime != lastReadReportTime) {
            this.lastReadReportTime = lastReadReportTime;
            setUpdateOption();
        }
    }

    public long getTriedStoneNum() {
        return triedStoneNum;
    }

    public void setTriedStoneNum(long triedStoneNum) {
        if (!Objects.equals(this.triedStoneNum, triedStoneNum)) {
            this.triedStoneNum = triedStoneNum;
            setUpdateOption();
        }
    }

    public Map<Integer, Integer> getTouchMallTimesMap() {
        return touchMallTimesMap;
    }

    public String getTouchMallTimesMapJsonStr() {
        return JSON.toJSONString(touchMallTimesMap);
    }

    public void setTouchMallTimesMap(Map<Integer, Integer> touchMallTimesMap) {
        this.touchMallTimesMap = touchMallTimesMap;
        setUpdateOption();
    }

    public int getTouchMallTimes(int mallId){
        if(touchMallTimesMap.containsKey(mallId)){
            return touchMallTimesMap.get(mallId);
        }
        return 0;
    }

    public void addTouchMallTimes(int mallId, int times){
        int totalTimes = getTouchMallTimes(mallId);
        totalTimes += times;
        touchMallTimesMap.put(mallId, totalTimes);
        setUpdateOption();
    }

    public void clearTouchMallTimes(int mallId){
        touchMallTimesMap.remove(mallId);
        setUpdateOption();
    }

    public void reduceTouchMallTimes(int mallId, int times){
        int totalTimes = getTouchMallTimes(mallId);
        totalTimes -= times;
        if(totalTimes < 0){
            totalTimes = 0;
        }
        touchMallTimesMap.put(mallId, totalTimes);
        setUpdateOption();
    }
}
